<template>
  <div class="feedback">
    <van-dialog
      v-model="show"
      show-cancel-button
      @confirm="onConfirm"
      :before-close="fn"
    >
      <template #title>
        <div class="content">
          <h3>意见反馈</h3>
          <van-field
            v-model="value"
            type="textarea"
            placeholder="请输入你对此问题的反馈意见"
            input-align="left"
          />
        </div>
      </template>
    </van-dialog>
  </div>
</template>

<script>
import { questionComment } from '@/api/api.js'
export default {
  props: ['testId'],
  data () {
    return {
      show: false,
      value: ''
    }
  },
  methods: {
    fn (action, done) {
      if (this.value.length === 0 && action === 'confirm') {
        done(false)
      } else {
        done()
      }
    },
    async onConfirm () {
      if (this.value.length === 0) {
        this.$toast('说点什么吧')
      } else {
        const res = await questionComment({
          content: this.value,
          question: this.testId
        })
        console.log(this.value)
        console.log(res)
        this.$toast('感谢你的反馈')
      }
    }
  }
}
</script>

<style lang="less">
.feedback {
  .content {
    height: 200px;
    padding: 0px 20px;
    h3 {
      margin-bottom: 20px;
    }
  }
}
</style>
